﻿using System;
using System.IO;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Xml;
using System.Windows.Forms;
using System.Text.RegularExpressions;
using WMSABL;
using WMSABL.SY;
using WMSAML.SY;
using WMSABL.Warehouse;
using ElectronicWMSA.Comm.ClassFiles;
using ElectronicWMSA.Comm.Forms.Message;

namespace ElectronicWMSA.Warehouse
{
    public partial class WarehouseFrm : Form
    {
        private string strWhere = "";
        private int PD_LayoutNID = 0;
        private string PD_LayoutField = "";
        private string WarehouseCode = "";
        private string Area = "";
        private string Postion = "";
        DataSet ds = new DataSet();
        PD_LayoutUpdateBLL bll = new PD_LayoutUpdateBLL();
        PublicDataSet bll_PublicDataSet = new PublicDataSet();
        private int SH = 0;
        private int SW = 0;
        public WarehouseFrm()
        {
            InitializeComponent();
            #region
            int H1 = 0;
            int H2 = 0;
            if (File.Exists("SytemConfig.xml"))
            {
                XmlDocument xmldoc = new XmlDocument();
                xmldoc.Load("SytemConfig.xml");
                foreach (XmlNode item in xmldoc.GetElementsByTagName("DOC"))
                {
                    foreach (XmlNode items in item.ChildNodes)
                    {
                        if (items.Name == "H1")
                            H1 = Convert.ToInt32(items.InnerText.Trim());
                        else if (items.Name == "H2")
                            H2 = Convert.ToInt32(items.InnerText.Trim());
                    }
                }
            }
            SH = Screen.PrimaryScreen.Bounds.Height;
            SW = Screen.PrimaryScreen.Bounds.Width;
            if (SH == 768 && SW == 1366)
                dataGridView1.RowTemplate.Height = H1;
            else if (SH == 1080 && SW == 1920)
                dataGridView1.RowTemplate.Height = H2;
            else if (SH == 1050 && SW == 1680)
                dataGridView1.RowTemplate.Height = H2;
            else if (SH > 1050)
                dataGridView1.RowTemplate.Height = H2;
            else if (SH == 768 && SW == 1024)
                dataGridView1.RowTemplate.Height = H1;
            else
                dataGridView1.RowTemplate.Height = H1;
            #endregion
            SetStyle(ControlStyles.UserPaint, true);
            SetStyle(ControlStyles.AllPaintingInWmPaint, true); // 禁止擦除背景.  
            SetStyle(ControlStyles.DoubleBuffer, true);
            this.dataGridView1.AllowUserToResizeColumns = false;
            this.dataGridView1.AllowUserToResizeRows = false;
        }
        private void WarehouseFrm_Load(object sender, EventArgs e)
        {
            this.strWhere = "";
            this.pageControl1.PageCurrent = 1;
            this.pageControl1.PageSize = 500;
            this.pageControl1.Bind();
            this.dataGridView1.CellBorderStyle = DataGridViewCellBorderStyle.None;
        }
        private int DBind()
        {
            ElectronicWMSA.Comm.Forms.MsControls.PageData pageData = new ElectronicWMSA.Comm.Forms.MsControls.PageData();
            pageData.TableName = "PD_Layout";
            pageData.PrimaryKey = "NID";
            pageData.OrderStr = "NID";
            pageData.PageIndex = this.pageControl1.PageCurrent;
            pageData.PageSize = this.pageControl1.PageSize;
            pageData.QueryCondition = strWhere;
            pageData.QueryFieldName = "*";

            this.pageControl1.bindingSource.DataSource = pageData.QueryDataTable().Tables[0];
            this.pageControl1.bindingNavigator.BindingSource = pageControl1.bindingSource;
            this.dataGridView1.AutoGenerateColumns = false;
            this.dataGridView1.DataSource = this.pageControl1.bindingSource;
            SystemVariable.DataGridViewStyle(dataGridView1);

            //for (int i = 0; i < dataGridView1.Rows.Count; i++)
            //{
            //    if (dataGridView1.Rows[i].Cells["txt"].Value.ToString() == "10")
            //    {
            //        dataGridView1.Rows[i].Height = 7;
            //        dataGridView1.Rows[i].DefaultCellStyle.BackColor = Color_value;
            //    }
            //    else if (dataGridView1.Rows[i].Cells["txt"].Value.ToString() == "宽")
            //    {
            //        dataGridView1.Rows[i].DefaultCellStyle.BackColor = Color_value;
            //    }
            //}

            if (checkBoxLineShow.Checked)
                dataGridView1.CellBorderStyle = DataGridViewCellBorderStyle.Single;
            else
                dataGridView1.CellBorderStyle = DataGridViewCellBorderStyle.None;

            if (SH > 768 && SW > 1366)
            {
                dataGridView1.RowsDefaultCellStyle.Font = new Font("微软雅黑", 6, FontStyle.Regular);
                dataGridView1.Rows[0].DefaultCellStyle.Font = new Font("微软雅黑", 10, FontStyle.Regular);
                dataGridView1.Rows[dataGridView1.Rows.Count - 1].DefaultCellStyle.Font = new Font("微软雅黑", 10, FontStyle.Regular);
            }
            else
            {
                dataGridView1.RowsDefaultCellStyle.Font = new Font("微软雅黑", 4, FontStyle.Regular);
                dataGridView1.Rows[0].DefaultCellStyle.Font = new Font("微软雅黑", 6, FontStyle.Regular);
                dataGridView1.Rows[dataGridView1.Rows.Count - 1].DefaultCellStyle.Font = new Font("微软雅黑", 6, FontStyle.Regular);
            }

            dataGridView1.Rows[0].DefaultCellStyle.BackColor = System.Drawing.Color.MediumSeaGreen;
            dataGridView1.Rows[dataGridView1.RowCount - 1].DefaultCellStyle.BackColor = System.Drawing.Color.MediumSeaGreen;
            return pageData.TotalCount;
        }
        Color Color_value = System.Drawing.Color.White;
        private int pageControlU_EventPaging(ElectronicWMSA.Comm.Forms.MsControls.EventPagingArg e)
        {
            return DBind();
        }

        private int SelectRowindex = -1;
        private int selectColumnIndex = 0;

        private int IndexRows = 0;//空行
        private int IndexRight = 0;//空列右
        private int IndexCenter = 0;//空列中
        private int IndexLeft = 0;//空列左
        private void dataGridViewUserList_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            IndexRows = 0;//空行
            IndexRight = 0;//空列右
            IndexCenter = 0;//空列中
            IndexLeft = 0;//空列左
            SelectRowindex = -1;
            if (e.RowIndex > 0 && e.ColumnIndex > 1)
            {
                SelectRowindex = e.RowIndex;
                selectColumnIndex = e.ColumnIndex;

                PD_LayoutNID = Convert.ToInt32(dataGridView1.Rows[e.RowIndex].Cells["NID"].Value);
                PD_LayoutField = dataGridView1.Columns[e.ColumnIndex].HeaderText.ToString();
                if (dataGridView1.Rows[dataGridView1.RowCount - 1].Cells[e.ColumnIndex].Value != null)
                {
                    Area = dataGridView1.Rows[dataGridView1.RowCount - 1].Cells[e.ColumnIndex].Value.ToString();
                    Postion = dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString();

                    //取上下
                    if (dataGridView1.Rows[e.RowIndex - 1].Cells[e.ColumnIndex].Value.ToString() == "" && dataGridView1.Rows[e.RowIndex + 1].Cells[e.ColumnIndex].Value.ToString() == "")
                    {
                        IndexRows = e.RowIndex + 1;
                        IndexCenter = e.ColumnIndex;
                    }
                    else if (dataGridView1.Rows[e.RowIndex - 1].Cells[e.ColumnIndex].Value.ToString() == "" && dataGridView1.Rows[e.RowIndex + 1].Cells[e.ColumnIndex].Value.ToString() != "")
                    {
                        IndexRows = e.RowIndex - 1;
                        IndexCenter = e.ColumnIndex;
                    }
                    else if (dataGridView1.Rows[e.RowIndex - 1].Cells[e.ColumnIndex].Value.ToString() != "" && dataGridView1.Rows[e.RowIndex + 1].Cells[e.ColumnIndex].Value.ToString() == "")
                    {
                        IndexRows = e.RowIndex + 1;
                        IndexCenter = e.ColumnIndex;
                    }



                    else if (dataGridView1.Rows[e.RowIndex - 1].Cells[e.ColumnIndex].Value.ToString() != "" && dataGridView1.Rows[e.RowIndex + 1].Cells[e.ColumnIndex].Value.ToString() != "")
                    {
                        if (dataGridView1.Rows[e.RowIndex - 2].Cells[e.ColumnIndex].Value.ToString() == "" && dataGridView1.Rows[e.RowIndex + 2].Cells[e.ColumnIndex].Value.ToString() == "")
                        {
                            IndexRows = e.RowIndex + 2;
                            IndexCenter = e.ColumnIndex;
                        }
                        else if (dataGridView1.Rows[e.RowIndex - 2].Cells[e.ColumnIndex].Value.ToString() == "" && dataGridView1.Rows[e.RowIndex + 2].Cells[e.ColumnIndex].Value.ToString() != "")
                        {
                            IndexRows = e.RowIndex - 2;
                            IndexCenter = e.ColumnIndex;
                        }
                        else if (dataGridView1.Rows[e.RowIndex - 2].Cells[e.ColumnIndex].Value.ToString() != "" && dataGridView1.Rows[e.RowIndex + 2].Cells[e.ColumnIndex].Value.ToString() == "")
                        {
                            IndexRows = e.RowIndex + 2;
                            IndexCenter = e.ColumnIndex;
                        }
                        else
                        {
                            if (dataGridView1.Rows[e.RowIndex - 3].Cells[e.ColumnIndex].Value.ToString() == "" && dataGridView1.Rows[e.RowIndex + 3].Cells[e.ColumnIndex].Value.ToString() == "")
                            {
                                IndexRows = e.RowIndex + 3;
                                IndexCenter = e.ColumnIndex;
                            }
                            else if (dataGridView1.Rows[e.RowIndex - 3].Cells[e.ColumnIndex].Value.ToString() == "" && dataGridView1.Rows[e.RowIndex + 3].Cells[e.ColumnIndex].Value.ToString() != "")
                            {
                                IndexRows = e.RowIndex - 3;
                                IndexCenter = e.ColumnIndex;
                            }
                            else if (dataGridView1.Rows[e.RowIndex - 3].Cells[e.ColumnIndex].Value.ToString() != "" && dataGridView1.Rows[e.RowIndex + 3].Cells[e.ColumnIndex].Value.ToString() == "")
                            {
                                IndexRows = e.RowIndex + 3;
                                IndexCenter = e.ColumnIndex;
                            }
                        }
                    }

                    //取左右 
                    for (int i = e.ColumnIndex; i < dataGridView1.ColumnCount; i++)
                    {
                        if (dataGridView1.Rows[e.RowIndex].Cells[i].Value.ToString() == "")
                        {
                            IndexRight = i;
                            break;
                        }
                    }

                    for (int i = e.ColumnIndex; i > -1; i--)
                    {
                        if (dataGridView1.Rows[e.RowIndex].Cells[i].Value.ToString() == "")
                        {
                            IndexLeft = i;
                            break;
                        }
                    }
                }
            }
        }
        private void dataGridView1_MouseClick(object sender, MouseEventArgs e)
        {
            if (SelectRowindex > -1 && e.Button == MouseButtons.Right)
            {
                this.dataGridView1.Rows[SelectRowindex].DefaultCellStyle.BackColor = System.Drawing.Color.Gainsboro;
                Postion_LayoutUpdateFrm frm = new Postion_LayoutUpdateFrm(WarehouseCode, Area, Postion);
                frm.ShowDialog();
                if (Postion != Postion_LayoutUpdateFrm.ValueStyle)
                {
                    bll.Update(PD_LayoutNID, PD_LayoutField, Postion_LayoutUpdateFrm.ValueStyle);
                    dataGridView1.Rows[SelectRowindex].Cells[selectColumnIndex].Value = Postion_LayoutUpdateFrm.ValueStyle;
                    this.dataGridView1.ClearSelection();
                }
            }
        }

        List<Point> list = new List<Point>();
        /// <summary>
        /// 保存上一次选中的区域
        /// </summary>
        public static string paitonCode1 = "";
        public static string paitonCode2 = "";
        private void dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex > -1 && e.ColumnIndex != -1)
            {
                if (Postion != "")
                {
                    list.Clear();
                    this.dataGridView1.Rows[SelectRowindex].DefaultCellStyle.BackColor = System.Drawing.Color.Gainsboro;
                    PointFunction(list, e.RowIndex, e.ColumnIndex);
                    Postion_LayoutFrm frm = new Postion_LayoutFrm(PD_LayoutNID, PD_LayoutField, list, paitonCode1, paitonCode2);
                    frm.ShowDialog();
                    paitonCode1 = frm.var1;
                    paitonCode2 = frm.var2;
                    if (frm.isture)
                    {
                        this.dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Style.BackColor = System.Drawing.Color.Red;
                        this.dataGridView1.ClearSelection();
                    }
                }
            }
        }
        Rectangle rec;
        private void PointFunction(List<Point> Pointlist, int row, int coloumn)
        {
            rec = this.dataGridView1.GetCellDisplayRectangle(IndexLeft, IndexRows, false);//左
            Pointlist.Add(new Point(rec.X + rec.Width / 2, rec.Y + rec.Height / 2));

            rec = this.dataGridView1.GetCellDisplayRectangle(IndexCenter, IndexRows, false);//中
            Pointlist.Add(new Point(rec.X + rec.Width / 2, rec.Y + rec.Height / 2));

            rec = this.dataGridView1.GetCellDisplayRectangle(coloumn, row, false);//原
            Pointlist.Add(new Point(rec.X + rec.Width / 2, rec.Y + rec.Height / 2));

            rec = this.dataGridView1.GetCellDisplayRectangle(IndexCenter, IndexRows, false);//中
            Pointlist.Add(new Point(rec.X + rec.Width / 2, rec.Y + rec.Height / 2));

            rec = this.dataGridView1.GetCellDisplayRectangle(IndexRight, IndexRows, false);//右
            Pointlist.Add(new Point(rec.X + rec.Width / 2, rec.Y + rec.Height / 2));
        }

        private void btnAlreadyDssigned_Click(object sender, EventArgs e)
        {
            this.pageControl1.Bind();
            ds = new DataSet();
            ds = bll_PublicDataSet.GetDataSet("select A.Layout_NID,A.Layout_Field from PD_PostionToLayout as A left join T_Stock as B on A.PositionNO=B.Posiont1 where Stauts=0  group by A.Layout_NID,A.Layout_Field");
            if (ds.Tables[0].Rows.Count > 0)
            {
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    for (int j = 0; j < dataGridView1.RowCount; j++)
                    {
                        if (dataGridView1.Rows[j].Cells["NID"].Value.ToString() == ds.Tables[0].Rows[i]["Layout_NID"].ToString())
                        {
                            for (int y = 0; y < dataGridView1.ColumnCount; y++)
                            {
                                if (dataGridView1.Columns[y].HeaderText == ds.Tables[0].Rows[i]["Layout_Field"].ToString())
                                {
                                    dataGridView1.Rows[j].Cells[y].Style.BackColor = System.Drawing.Color.Red;
                                    break;
                                }
                            }
                            break;
                        }
                    }
                }
            }
        }
        private void btnClearShow_Click(object sender, EventArgs e)
        {
            this.pageControl1.Bind();
        }
        private void btnClose_Click(object sender, EventArgs e)
        {
            this.Close();
        }


        /// <summary>
        /// 网格显示
        /// </summary>
        private void checkBoxLineShow_Click(object sender, EventArgs e)
        {
            if (checkBoxLineShow.Checked)
            {
                dataGridView1.CellBorderStyle = DataGridViewCellBorderStyle.Single;
            }
            else
            {
                dataGridView1.CellBorderStyle = DataGridViewCellBorderStyle.None;
            }
        }
        /// <summary>
        /// 布局反向
        /// </summary>
        private void checkBoxDirection_Click(object sender, EventArgs e)
        {
            if (checkBoxDirection.Checked)
            {
                #region 排序
                this.dataGridView1.Columns[0].DisplayIndex = 56;
                this.dataGridView1.Columns[1].DisplayIndex = 55;
                this.dataGridView1.Columns[2].DisplayIndex = 54;
                this.dataGridView1.Columns[3].DisplayIndex = 53;
                this.dataGridView1.Columns[4].DisplayIndex = 52;
                this.dataGridView1.Columns[5].DisplayIndex = 51;
                this.dataGridView1.Columns[6].DisplayIndex = 50;

                this.dataGridView1.Columns[7].DisplayIndex = 49;
                this.dataGridView1.Columns[8].DisplayIndex = 48;
                this.dataGridView1.Columns[9].DisplayIndex = 47;
                this.dataGridView1.Columns[10].DisplayIndex = 46;
                this.dataGridView1.Columns[11].DisplayIndex = 45;
                this.dataGridView1.Columns[12].DisplayIndex = 44;
                this.dataGridView1.Columns[13].DisplayIndex = 43;
                this.dataGridView1.Columns[14].DisplayIndex = 42;
                this.dataGridView1.Columns[15].DisplayIndex = 41;
                this.dataGridView1.Columns[16].DisplayIndex = 40;

                this.dataGridView1.Columns[17].DisplayIndex = 39;
                this.dataGridView1.Columns[18].DisplayIndex = 38;
                this.dataGridView1.Columns[19].DisplayIndex = 37;
                this.dataGridView1.Columns[20].DisplayIndex = 36;
                this.dataGridView1.Columns[21].DisplayIndex = 35;
                this.dataGridView1.Columns[22].DisplayIndex = 34;
                this.dataGridView1.Columns[23].DisplayIndex = 33;
                this.dataGridView1.Columns[24].DisplayIndex = 32;
                this.dataGridView1.Columns[25].DisplayIndex = 31;
                this.dataGridView1.Columns[26].DisplayIndex = 30;

                this.dataGridView1.Columns[27].DisplayIndex = 29;
                this.dataGridView1.Columns[28].DisplayIndex = 28;
                this.dataGridView1.Columns[29].DisplayIndex = 27;
                this.dataGridView1.Columns[30].DisplayIndex = 26;
                this.dataGridView1.Columns[31].DisplayIndex = 25;
                this.dataGridView1.Columns[32].DisplayIndex = 24;
                this.dataGridView1.Columns[33].DisplayIndex = 23;
                this.dataGridView1.Columns[34].DisplayIndex = 22;
                this.dataGridView1.Columns[35].DisplayIndex = 21;
                this.dataGridView1.Columns[36].DisplayIndex = 20;

                this.dataGridView1.Columns[37].DisplayIndex = 19;
                this.dataGridView1.Columns[38].DisplayIndex = 18;
                this.dataGridView1.Columns[39].DisplayIndex = 17;
                this.dataGridView1.Columns[40].DisplayIndex = 16;
                this.dataGridView1.Columns[41].DisplayIndex = 15;
                this.dataGridView1.Columns[42].DisplayIndex = 14;
                this.dataGridView1.Columns[43].DisplayIndex = 13;
                this.dataGridView1.Columns[44].DisplayIndex = 12;
                this.dataGridView1.Columns[45].DisplayIndex = 11;
                this.dataGridView1.Columns[46].DisplayIndex = 10;

                this.dataGridView1.Columns[47].DisplayIndex = 9;
                this.dataGridView1.Columns[48].DisplayIndex = 8;
                this.dataGridView1.Columns[49].DisplayIndex = 7;
                this.dataGridView1.Columns[50].DisplayIndex = 6;
                this.dataGridView1.Columns[51].DisplayIndex = 5;
                this.dataGridView1.Columns[52].DisplayIndex = 4;
                this.dataGridView1.Columns[53].DisplayIndex = 3;
                this.dataGridView1.Columns[54].DisplayIndex = 2;
                this.dataGridView1.Columns[55].DisplayIndex = 1;
                this.dataGridView1.Columns[56].DisplayIndex = 0;
                #endregion
            }
            else
            {
                #region 排序
                this.dataGridView1.Columns[0].DisplayIndex = 0;
                this.dataGridView1.Columns[1].DisplayIndex = 1;
                this.dataGridView1.Columns[2].DisplayIndex = 2;
                this.dataGridView1.Columns[3].DisplayIndex = 3;
                this.dataGridView1.Columns[4].DisplayIndex = 4;
                this.dataGridView1.Columns[5].DisplayIndex = 5;
                this.dataGridView1.Columns[6].DisplayIndex = 6;
                this.dataGridView1.Columns[7].DisplayIndex = 7;
                this.dataGridView1.Columns[8].DisplayIndex = 8;
                this.dataGridView1.Columns[9].DisplayIndex = 9;
                this.dataGridView1.Columns[10].DisplayIndex = 10;
                this.dataGridView1.Columns[11].DisplayIndex = 11;
                this.dataGridView1.Columns[12].DisplayIndex = 12;
                this.dataGridView1.Columns[13].DisplayIndex = 13;
                this.dataGridView1.Columns[14].DisplayIndex = 14;
                this.dataGridView1.Columns[15].DisplayIndex = 15;
                this.dataGridView1.Columns[16].DisplayIndex = 16;
                this.dataGridView1.Columns[17].DisplayIndex = 17;
                this.dataGridView1.Columns[18].DisplayIndex = 18;
                this.dataGridView1.Columns[19].DisplayIndex = 19;
                this.dataGridView1.Columns[20].DisplayIndex = 20;
                this.dataGridView1.Columns[21].DisplayIndex = 21;
                this.dataGridView1.Columns[22].DisplayIndex = 22;
                this.dataGridView1.Columns[23].DisplayIndex = 23;
                this.dataGridView1.Columns[24].DisplayIndex = 24;
                this.dataGridView1.Columns[25].DisplayIndex = 25;
                this.dataGridView1.Columns[26].DisplayIndex = 26;
                this.dataGridView1.Columns[27].DisplayIndex = 27;
                this.dataGridView1.Columns[28].DisplayIndex = 28;
                this.dataGridView1.Columns[29].DisplayIndex = 29;
                this.dataGridView1.Columns[30].DisplayIndex = 30;
                this.dataGridView1.Columns[31].DisplayIndex = 31;
                this.dataGridView1.Columns[32].DisplayIndex = 32;
                this.dataGridView1.Columns[33].DisplayIndex = 33;
                this.dataGridView1.Columns[34].DisplayIndex = 34;
                this.dataGridView1.Columns[35].DisplayIndex = 35;
                this.dataGridView1.Columns[36].DisplayIndex = 36;
                this.dataGridView1.Columns[37].DisplayIndex = 37;
                this.dataGridView1.Columns[38].DisplayIndex = 38;
                this.dataGridView1.Columns[39].DisplayIndex = 39;
                this.dataGridView1.Columns[40].DisplayIndex = 40;
                this.dataGridView1.Columns[41].DisplayIndex = 41;
                this.dataGridView1.Columns[42].DisplayIndex = 42;
                this.dataGridView1.Columns[43].DisplayIndex = 43;
                this.dataGridView1.Columns[44].DisplayIndex = 44;
                this.dataGridView1.Columns[45].DisplayIndex = 45;
                this.dataGridView1.Columns[46].DisplayIndex = 46;
                this.dataGridView1.Columns[47].DisplayIndex = 47;
                this.dataGridView1.Columns[48].DisplayIndex = 48;
                this.dataGridView1.Columns[49].DisplayIndex = 49;
                this.dataGridView1.Columns[50].DisplayIndex = 50;
                this.dataGridView1.Columns[51].DisplayIndex = 51;
                this.dataGridView1.Columns[52].DisplayIndex = 52;
                this.dataGridView1.Columns[53].DisplayIndex = 53;
                this.dataGridView1.Columns[54].DisplayIndex = 54;
                this.dataGridView1.Columns[55].DisplayIndex = 55;
                this.dataGridView1.Columns[56].DisplayIndex = 56;
                #endregion
            }
        }
        #region  显示地址码
        /// <summary>
        /// 地址码信息
        /// </summary>
        private string PostionStrNo = "";
        private void dataGridView1_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e)
        {
            PostionStrNo = "";
            仓位地址码ToolStripMenuItem.Text = "";
            if (e.Button == System.Windows.Forms.MouseButtons.Left && e.ColumnIndex > -1 && e.RowIndex > -1)  //点击的是鼠标右键，并且不是表头
            {
                this.dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Selected = true;

                DataSet dsFiled = new DataSet();

                if (PD_LayoutField != "" && dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString() != "")
                {
                    dsFiled = bll_PublicDataSet.GetDataSet("select PositionNO from [dbo].[PD_PostionToLayout] where Layout_NID='" + PD_LayoutNID + "' and Layout_Field='" + PD_LayoutField + "'and Stauts=0 ");
                    if (dsFiled != null && dsFiled.Tables[0].Rows.Count > 0)
                    {
                        PostionStrNo = "";
                        for (int i = 0; i < dsFiled.Tables[0].Rows.Count; i++)
                        {
                            PostionStrNo += dsFiled.Tables[0].Rows[i]["PositionNO"].ToString() + ";\n";
                        }
                    }
                    if (PostionStrNo != "")
                    {
                        this.contextMenuStrip1.Show(MousePosition.X + 5, MousePosition.Y + 5);
                        仓位地址码ToolStripMenuItem.Text = "";
                        仓位地址码ToolStripMenuItem.Text = PostionStrNo;
                    }
                }
            }
        }

        private void dataGridView1_CellMouseEnter(object sender, DataGridViewCellEventArgs e)
        {
            //PostionStrNo = "";
            //仓位地址码ToolStripMenuItem.Text = "";

            //this.dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Selected = true;

            //DataSet dsFiled = new DataSet();

            //if (PD_LayoutField != "" && dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString() != "")
            //{
            //    dsFiled = bll_PublicDataSet.GetDataSet("select PositionNO from [dbo].[PD_PostionToLayout] where Layout_NID='" + PD_LayoutNID + "' and Layout_Field='" + PD_LayoutField + "'and Stauts=0 ");
            //    if (dsFiled != null && dsFiled.Tables[0].Rows.Count > 0)
            //    {
            //        PostionStrNo = "";
            //        for (int i = 0; i < dsFiled.Tables[0].Rows.Count; i++)
            //        {
            //            PostionStrNo += dsFiled.Tables[0].Rows[i]["PositionNO"].ToString() + ";\n";
            //        }
            //    }
            //    if (PostionStrNo != "")
            //    {
            //        this.contextMenuStrip1.Show(MousePosition.X + 5, MousePosition.Y + 5);
            //        仓位地址码ToolStripMenuItem.Text = "";
            //        仓位地址码ToolStripMenuItem.Text = PostionStrNo;
            //    }

            //}
        }
        #endregion
    }
}
